﻿Imports System.IO
Imports System.Data.SqlClient
Imports System.Data.OleDb
Imports System.Data.Common


Public Class UserControlInterface

    'The constantPaddingForUserControlInterfaceReferences variable 
    'is used to keep the constant distance between 
    'the UserControls(UserControlReferences),which are depicted on the 
    'BASIC USERCONTROL(UserControlInterface)
    Public Const CONSTANT_PADDING_FOR_UserControlReferences As Integer = 120

    'This helps adding a new user control reference
    'If is True means that a new reference is adding in list 
    'of references
    'If is false means that user update older user control reference
    Public Shared newRefIsAdding As Integer = False

    'Just for help,Keeps Local the sql string for operations
    Dim strSQL As String

    Public Sub addToSpecificUserControlInterfaceInfo(ByVal advertEventID, ByVal userControlWhichIsCreatedNow)
        
        Try

            'SQL statement for specific line of the basic table
            '(LOOK advertEventID) => Specific UserControlInterface
            strSQL = "SELECT * " & _
                     "FROM Adevents a, SiteConnection sc, AdConnection adc, " & _
                     "TypeConnection tc, UserConnection uc, AdvertiserConnection ac, RecordingConnection rc " & _
                     "WHERE a.eventSiteID = sc.eventSiteID AND " & _
                     "a.eventAdID = adc.eventAdID AND " & _
                     "a.eventTypeID = tc.eventTypeID AND " & _
                     "a.eventUserID = uc.eventUserID AND " & _
                     "a.eventAdvertiserID = ac.eventAdvertiserID AND " & _
                     "a.RecordingID = rc.RecordingID AND " & _
                     "a.adEventID = " & advertEventID.ToString & " AND refEventID = -1 ; "

            'Here we get and set the info of basic 
            'UserControl(UserControlInterface)
            DataBaseLibrary.setTheDataFomDataBase(strSQL, Me)

            'Add references
            addReferencesToSpecificUserControlInterface(advertEventID, userControlWhichIsCreatedNow)


        Catch ex As Exception
            MsgBox("Not add a specific User Control Info", vbExclamation, "BE CAREFUL")
        End Try
        
    End Sub

    Public Sub addReferencesToSpecificUserControlInterface(ByVal advertEventID, ByVal userControlWhichIsCreatedNow)

        Try

            'Here we will count with the 
            'numberOfExistingUserControlsInterfaceReferences variable the n
            'umber of UserControls,which is referenced to basic UserControl
            '(UserControlInterface)
            '( LOOK a.refEventID = advertEventID.ToString )
            strSQL = "SELECT COUNT(*) AS C " & _
                     "FROM Adevents a, SiteConnection sc, AdConnection adc, " & _
                     "TypeConnection tc, UserConnection uc, AdvertiserConnection ac, RecordingConnection rc " & _
                     "WHERE a.eventSiteID = sc.eventSiteID AND " & _
                     "a.eventAdID = adc.eventAdID AND " & _
                     "a.eventTypeID = tc.eventTypeID AND " & _
                     "a.eventUserID = uc.eventUserID AND " & _
                     "a.eventAdvertiserID = ac.eventAdvertiserID AND " & _
                     "a.RecordingID = rc.RecordingID AND " & _
                     "a.refEventID = " & advertEventID.ToString & "; "

            'Here we get and set the info of 
            'UserControl(UserControlReferences)
            Dim numberOfUserControlsReferencesForBasicUserControl As Integer = 0
            DataBaseLibrary.getCountResultFromDataBase(strSQL, numberOfUserControlsReferencesForBasicUserControl)

            'We change the location of all basic user controls
            'So, we can add the new user control reference
            For i = Form1.numberOfExistingUserControlsInterface - 1 To userControlWhichIsCreatedNow + 1 Step -1
                Form1.listForUserControlsInterface(i).Location = New Point((My.Computer.Screen.Bounds.Width - Form1.listForUserControlsInterface(i).Width) / 2, Form1.listForUserControlsInterface(i).Location.Y + numberOfUserControlsReferencesForBasicUserControl * CONSTANT_PADDING_FOR_UserControlReferences)
            Next

            'Don't forget that for every basic 
            'UserControl(UserControlInterface) we must know the other 
            'UserControls,which reference to this basic specific UserControl.
            'So we are going to use the adEventID variable.This will help 
            'us to match adEventID of this specific basic UserControl with 
            'the refEventID of the other UserControls and so we will know 
            'the references of this basic UserControl(UserControlInterface)
            'Here we are working now in ONE specific basic 
            'UserControl(UserControlInterface)

            'So, as we have the total number of the UserControls which 
            'reference to specific UserControlInterface(Basic),we make 
            'the list for the reference UserControl(UserControlReferences)
            'and of course we ADD every reference UserControl ON the 
            'specific UserControlInterface(Basic) with the appropriate 
            'Location.
            'But here we will get first the NUMBER of the 
            'reference UserControl, that we are going to use.
            'These UserControls don't have Information yet!

            'help is a specific UserControlInterface
            Dim help = Form1.listForUserControlsInterface(userControlWhichIsCreatedNow)

            'Change UserControlInterface sizes to be correct with the number
            'of its references
            help.Size = New System.Drawing.Size(help.Width, help.Height + numberOfUserControlsReferencesForBasicUserControl * CONSTANT_PADDING_FOR_UserControlReferences)
            help.Panel1.Size = New System.Drawing.Size(help.Panel1.Width, help.Panel1.Height + numberOfUserControlsReferencesForBasicUserControl * CONSTANT_PADDING_FOR_UserControlReferences)
            help.PanelForReferences.Size = New System.Drawing.Size(help.PanelForReferences.Width, numberOfUserControlsReferencesForBasicUserControl * CONSTANT_PADDING_FOR_UserControlReferences)

            'Make the list of references
            Dim listOfReferencesForSpecificUserControls As New List(Of UserControlReferences)
            For i As Integer = 0 To numberOfUserControlsReferencesForBasicUserControl - 1
                Dim elementOfReferencesForSpecificUserControls = New UserControlReferences()

                elementOfReferencesForSpecificUserControls.DeleteButton.Tag = i
                elementOfReferencesForSpecificUserControls.SaveReferenceLinkLabel.Tag = i
                elementOfReferencesForSpecificUserControls.Location = New Point(0, i * CONSTANT_PADDING_FOR_UserControlReferences)

                help.PanelForReferences.Controls.Add(elementOfReferencesForSpecificUserControls)
                listOfReferencesForSpecificUserControls.Add(elementOfReferencesForSpecificUserControls)

            Next
            help.setReferenceList(listOfReferencesForSpecificUserControls)

            'Here we get from DB and set the Information of any reference 
            'UserControl,which reference to a specific basic 
            'UserControl(UserControlInterface) 
            strSQL = "SELECT * " & _
                     "FROM Adevents a, SiteConnection sc, AdConnection adc, " & _
                     "TypeConnection tc, UserConnection uc, AdvertiserConnection ac, RecordingConnection rc " & _
                     "WHERE a.eventSiteID = sc.eventSiteID AND " & _
                     "a.eventAdID = adc.eventAdID AND " & _
                     "a.eventTypeID = tc.eventTypeID AND " & _
                     "a.eventUserID = uc.eventUserID AND " & _
                     "a.eventAdvertiserID = ac.eventAdvertiserID AND " & _
                     "a.RecordingID = rc.RecordingID AND " & _
                     "a.refEventID = " & advertEventID.ToString & " ORDER BY EventDate ; "

            'Here we call method about info of UserControl(UserControlReferences)
            DataBaseLibrary.setTheDataFomDataBase(strSQL, listOfReferencesForSpecificUserControls)


        Catch ex As Exception
            MsgBox("Problem User Control References", vbExclamation, "BE CAREFUL")
        End Try
        
    End Sub

    Private Sub UserControlInterface_Click(sender As Object, e As System.EventArgs) Handles Me.Click
        'For mouse wheel
        Form1.PanelForAll.Select()
    End Sub

    Private Sub UserControlInterface_MouseClick(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseClick
        'For mouse wheel
        Form1.PanelForAll.Select()
    End Sub

    Private Sub UserControlInterface_MouseMove(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
        'For mouse wheel
        Form1.PanelForAll.Select()
    End Sub

    Private Sub PanelForAll_MouseDoubleClick(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDoubleClick
        'For mouse wheel
        Form1.PanelForAll.Select()
    End Sub

    Private Sub PanelForAll_MouseEnter(sender As Object, e As System.EventArgs) Handles Me.MouseEnter
        'For mouse wheel
        Form1.PanelForAll.Select()
    End Sub

    Private Sub PanelForAll_MouseLeave(sender As Object, e As System.EventArgs) Handles Me.MouseLeave
        'For mouse wheel
        Form1.PanelForAll.Select()
    End Sub

    Private Sub PanelForAll_MouseHover(sender As Object, e As System.EventArgs) Handles Me.MouseHover
        'For mouse wheel
        Form1.PanelForAll.Select()
    End Sub

    '//////////////////////////////////////////////////////////////////////////////





    '//////////////// METHODS OF USER CONTROL INTERFACE CONTROL ///////////////////

    Private Sub AddComment_LinkClicked(sender As System.Object, e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles AddComment.LinkClicked

        Try

            'Here we add new user control reference

            'We change the location of all existing user controls references
            'So, we can add the new user control reference
            For i = Form1.listForUserControlsInterface.Count - 1 To Me.PanelForReferences.Tag + 1 Step -1
                Form1.listForUserControlsInterface(i).Location = New Point((My.Computer.Screen.Bounds.Width - Form1.listForUserControlsInterface(i).Width) / 2, Form1.listForUserControlsInterface(i).Location.Y + CONSTANT_PADDING_FOR_UserControlReferences)
            Next

            'Change sizes 
            Me.Size = New System.Drawing.Size(Me.Width, Me.Height + CONSTANT_PADDING_FOR_UserControlReferences)
            Me.Panel1.Size = New System.Drawing.Size(Me.Panel1.Width, (Me.Panel1.Height + CONSTANT_PADDING_FOR_UserControlReferences))
            Me.PanelForReferences.Size = New System.Drawing.Size(Me.PanelForReferences.Width, Me.PanelForReferences.Height + CONSTANT_PADDING_FOR_UserControlReferences)

            'The new user control interface,which has the references
            Dim help = Form1.listForUserControlsInterface(Me.PanelForReferences.Tag)

            'The new user control reference
            Dim userControlReferencesAdded = New UserControlReferences()
            userControlReferencesAdded.Location = New Point(0, Me.PanelForReferences.Height - CONSTANT_PADDING_FOR_UserControlReferences)

            Dim timeStamp As DateTime = DateTime.Now
            userControlReferencesAdded.setEventDateValue(timeStamp)

            'Add new in reference list
            Try
                help.getReferenceList().Add(userControlReferencesAdded)
            Catch ex As Exception
                'Auto Save
                Form1.ControlSaving(False)
                help.getReferenceList().Add(userControlReferencesAdded)
            End Try

            'Add new in form
            Me.PanelForReferences.Controls.Add(userControlReferencesAdded)


            'Set appropriate info for new reference
            userControlReferencesAdded.DeleteButton.Tag = help.getReferenceList().Count - 1
            userControlReferencesAdded.SaveReferenceLinkLabel.Tag = help.getReferenceList().Count - 1

            ' "Send Message" to Save click that must add to database
            newRefIsAdding = True

        Catch ex As Exception
            MsgBox("Problem User Control Interface adding", vbExclamation, "BE CAREFUL")
        End Try

    End Sub

    Private Sub DeleteButton_Click(sender As System.Object, e As System.EventArgs) Handles DeleteButton.Click
        Try

            If Not Form1.listForUserControlsInterface.Count = 1 Then

                Dim ret = MsgBox("Are you sure about DELETE?", vbYesNo + vbCritical, "BE CAREFUL")
                If (ret.ToString = "Yes") = True Then


                    'The new user control interface,which will delete the reference
                    Dim help = Form1.listForUserControlsInterface(Me.DeleteButton.Tag)


                    'Delete Basic User Control References
                    strSQL = " DELETE FROM Adevents WHERE refEventID = " & help.getAdvertEventID & " ;"
                    DataBaseLibrary.updateUserControlsFromDataBase(strSQL)

                    'Delete Basic User Control References
                    strSQL = " DELETE FROM Adevents WHERE adEventID = " & help.getAdvertEventID & " ;"
                    DataBaseLibrary.updateUserControlsFromDataBase(strSQL)

                    'Remove from list
                    Form1.listForUserControlsInterface.RemoveAt(Me.DeleteButton.Tag)

                    Form1.BeForDispaying()

                End If
            Else
                MsgBox("Problem,You are trying to delete all saving User Controls", vbExclamation, "BE CAREFUL")
            End If
        Catch ex As Exception
            MsgBox("Problem User Control Interface deleting,May be you did not Saved it.", vbExclamation, "BE CAREFUL")
        End Try

    End Sub

    '//////////////////////////////////////////////////////////////////////////////





    '//////////////// METHODS OF USER CONTROL REFERENCE CONTROL ///////////////////

    Public Sub SaveReference(ByVal sender, ByVal thisUserControl)

        'Ok,here we are going to save the info of reference user control
        'either if the user control(UserControlReference) is 
        'new or we have changed an older.

        Try
            Dim ret = MsgBox("Are you sure about SAVE?", vbYesNo + vbCritical, "BE CAREFUL")
            If (ret.ToString = "Yes") = True Then



                'The new user control interface,which will save the references
                Dim help = Form1.listForUserControlsInterface(thisUserControl)

                'We look now if we have new or not 
                If newRefIsAdding = True Then

                    'We  have new 

                    'Save like Form1.vb
                    Dim addNewReferencesForSpecificUserControls = New UserControlReferences()

                    help.getReferenceList(sender).setEventSiteValue(help.getReferenceList(sender).getEventSiteValue())
                    help.getReferenceList(sender).setEventAdValue(help.getReferenceList(sender).getEventAdValue())
                    help.getReferenceList(sender).setEventTypeValue(help.getReferenceList(sender).getEventTypeValue())
                    help.getReferenceList(sender).setEventUserValue(help.getReferenceList(sender).getEventUserValue())
                    help.getReferenceList(sender).setEventAdvertiserValue(help.getReferenceList(sender).getEventAdvertiserValue())
                    help.getReferenceList(sender).setRecordingValue(help.getReferenceList(sender).getRecordingValue())

                    help.getReferenceList(sender).setEventValue(help.getReferenceList(sender).getEventValue())
                    help.getReferenceList(sender).setEventDateValue(help.getReferenceList(sender).getEventDateValue())

                    Dim SiteID = DataBaseLibrary.RecordExists("SiteConnection", "eventSiteID", "SiteName", help.getReferenceList(sender).getEventSiteValue())
                    If SiteID = 0 Then
                        SiteID = CInt(Math.Ceiling(Rnd() * 99).ToString & "2")
                        While DataBaseLibrary.IdRecordExists(SiteID.ToString, "SiteConnection", "eventSiteID") = True
                            SiteID = CInt(Math.Ceiling(Rnd() * 99).ToString & "2")
                        End While
                        help.getReferenceList(sender).setSiteEventID(SiteID)
                        strSQL = " INSERT INTO SiteConnection(eventSiteID, SiteName) VALUES (" & SiteID & " , '" & help.getReferenceList(sender).getEventSiteValue() & "');"
                        DataBaseLibrary.updateUserControlsFromDataBase(strSQL)
                    End If

                    Dim AdID = DataBaseLibrary.RecordExists("AdConnection", "eventAdID", "AdName", help.getReferenceList(sender).getEventAdValue())
                    If AdID = 0 Then
                        AdID = CInt(Math.Ceiling(Rnd() * 99).ToString & "3")
                        While DataBaseLibrary.IdRecordExists(AdID.ToString, "AdConnection", "eventAdID") = True
                            AdID = CInt(Math.Ceiling(Rnd() * 99).ToString & "3")
                        End While
                        help.getReferenceList(sender).setEventAdID(AdID)
                        strSQL = " INSERT INTO AdConnection(eventAdID, AdName) VALUES ( " & AdID & " , '" & help.getReferenceList(sender).getEventAdValue() & "');"
                        DataBaseLibrary.updateUserControlsFromDataBase(strSQL)
                    End If

                    Dim TypeID = DataBaseLibrary.RecordExists("TypeConnection", "eventTypeID", "TypeName", help.getReferenceList(sender).getEventTypeValue())
                    If TypeID = 0 Then
                        TypeID = CInt(Math.Ceiling(Rnd() * 99).ToString & "4")
                        While DataBaseLibrary.IdRecordExists(TypeID.ToString, "TypeConnection", "eventTypeID") = True
                            TypeID = CInt(Math.Ceiling(Rnd() * 99).ToString & "4")
                        End While
                        help.getReferenceList(sender).setTypeEventID(TypeID)
                        strSQL = " INSERT INTO TypeConnection(eventTypeID, TypeName) VALUES ( " & TypeID & ", '" & help.getReferenceList(sender).getEventTypeValue() & "');"
                        DataBaseLibrary.updateUserControlsFromDataBase(strSQL)
                    End If


                    Dim UserID = DataBaseLibrary.RecordExists("UserConnection", "eventUserID", "UserName", help.getReferenceList(sender).getEventUserValue())
                    If UserID = 0 Then
                        UserID = CInt(Math.Ceiling(Rnd() * 99).ToString & "5")
                        While DataBaseLibrary.IdRecordExists(UserID.ToString, "UserConnection", "eventUserID") = True
                            UserID = CInt(Math.Ceiling(Rnd() * 99).ToString & "5")
                        End While
                        help.getReferenceList(sender).setUserEventID(UserID)
                        strSQL = " INSERT INTO UserConnection(eventUserID, UserName) VALUES ( " & UserID & ", '" & help.getReferenceList(sender).getEventUserValue() & "');"
                        DataBaseLibrary.updateUserControlsFromDataBase(strSQL)
                    End If


                    Dim AdvertiserID = DataBaseLibrary.RecordExists("AdvertiserConnection", "eventAdvertiserID", "AdvertiserName", help.getReferenceList(sender).getEventAdvertiserValue())
                    If AdvertiserID = 0 Then
                        AdvertiserID = CInt(Math.Ceiling(Rnd() * 99).ToString & "6")
                        While DataBaseLibrary.IdRecordExists(AdvertiserID.ToString, "AdvertiserConnection", "eventAdvertiserID") = True
                            AdvertiserID = CInt(Math.Ceiling(Rnd() * 99).ToString & "6")
                        End While
                        help.getReferenceList(sender).setAdvertiserEventID(AdvertiserID)
                        strSQL = " INSERT INTO AdvertiserConnection(eventAdvertiserID, AdvertiserName) VALUES ( " & AdvertiserID & ", '" & help.getReferenceList(sender).getEventAdvertiserValue() & "');"
                        DataBaseLibrary.updateUserControlsFromDataBase(strSQL)
                    End If


                    Dim RecID = DataBaseLibrary.RecordExists("RecordingConnection", "RecordingID", "RecordingName", help.getReferenceList(sender).getRecordingValue())
                    If RecID = 0 Then
                        RecID = CInt(Math.Ceiling(Rnd() * 99).ToString & "7")
                        While DataBaseLibrary.IdRecordExists(RecID.ToString, "RecordingConnection", "RecordingID") = True
                            RecID = CInt(Math.Ceiling(Rnd() * 99).ToString & "7")
                        End While
                        help.getReferenceList(sender).setRecordingID(RecID)
                        strSQL = " INSERT INTO RecordingConnection(RecordingID, RecordingName) VALUES ( " & RecID & ", '" & help.getReferenceList(sender).getRecordingValue() & "');"
                        DataBaseLibrary.updateUserControlsFromDataBase(strSQL)
                    End If

                    Dim ID = CInt(Math.Ceiling(Rnd() * 99).ToString & "1")
                    While DataBaseLibrary.IdRecordExists(ID.ToString, "Adevents", "adEventID") = True
                        ID = CInt(Math.Ceiling(Rnd() * 99).ToString & "1")
                    End While
                    help.getReferenceList(sender).setAdvertEventID(ID)

                    strSQL = " INSERT INTO Adevents( " & _
                             " adEventID, " & _
                             " eventSiteID, " & _
                             " eventAdID, " & _
                             " eventTypeID, " & _
                             " eventUserID, " & _
                             " EventDate, " & _
                             " eventAdvertiserID, " & _
                             " RecordingID, " & _
                             " eventValue, " & _
                             " refEventID) VALUES " & _
                             " ( " & ID & " , " & SiteID & " , " & AdID & " , " & TypeID & " , " & UserID & " , " & DataBaseLibrary.ConvertDateForThisDataBase(help.getReferenceList(sender).getEventDateValue().ToString) & " , " & AdvertiserID & " , " & RecID & " , '" & help.getReferenceList(sender).getEventValue() & "' , " & help.getAdvertEventID & " ) ; "

                    DataBaseLibrary.updateUserControlsFromDataBase(strSQL)




                Else


                    'Update older reference

                    'Save like Form1.vb
                    strSQL = " UPDATE Adevents " & _
                             " SET " & _
                             " EventDate = " & _
                             DataBaseLibrary.ConvertDateForThisDataBase(help.getReferenceList(sender).getEventDateValue().ToString) & _
                             " WHERE " & _
                             " adEventID = " & help.getReferenceList(sender).getAdvertEventID() & ";"

                    DataBaseLibrary.updateUserControlsFromDataBase(strSQL)

                    strSQL = " UPDATE Adevents " & _
                             " SET " & _
                             " eventValue = '" & _
                             help.getReferenceList(sender).getEventValue() & _
                             "' WHERE " & _
                             " adEventID = " & help.getReferenceList(sender).getAdvertEventID() & ";"

                    DataBaseLibrary.updateUserControlsFromDataBase(strSQL)

                    strSQL = " UPDATE SiteConnection SET SiteName = '" & help.getReferenceList(sender).getEventSiteValue() & "' WHERE eventSiteID = " & help.getReferenceList(sender).getSiteEventID() & ";"
                    DataBaseLibrary.updateUserControlsFromDataBase(strSQL)

                    strSQL = " UPDATE AdConnection SET AdName = '" & help.getReferenceList(sender).getEventAdValue() & "' WHERE eventAdID = " & help.getReferenceList(sender).getEventAdID() & ";"
                    DataBaseLibrary.updateUserControlsFromDataBase(strSQL)

                    strSQL = " UPDATE TypeConnection SET TypeName = '" & help.getReferenceList(sender).getEventTypeValue() & "' WHERE eventTypeID = " & help.getReferenceList(sender).getTypeEventID() & ";"
                    DataBaseLibrary.updateUserControlsFromDataBase(strSQL)

                    strSQL = " UPDATE UserConnection SET UserName = '" & help.getReferenceList(sender).getEventUserValue() & "' WHERE eventUserID = " & help.getReferenceList(sender).getUserEventID() & ";"
                    DataBaseLibrary.updateUserControlsFromDataBase(strSQL)

                    strSQL = " UPDATE AdvertiserConnection SET AdvertiserName = '" & help.getReferenceList(sender).getEventAdvertiserValue() & "' WHERE eventAdvertiserID = " & help.getReferenceList(sender).getAdvertiserEventID() & ";"
                    DataBaseLibrary.updateUserControlsFromDataBase(strSQL)

                    strSQL = " UPDATE RecordingConnection SET RecordingName = '" & help.getReferenceList(sender).getRecordingValue() & "' WHERE RecordingID = " & help.getReferenceList(sender).getRecordingID() & ";"
                    DataBaseLibrary.updateUserControlsFromDataBase(strSQL)

                End If

                'RE initialize variable
                newRefIsAdding = False




            End If

        Catch ex As Exception
            MsgBox("Problem User Control References saving", vbExclamation, "BE CAREFUL")
        End Try

    End Sub

    Public Sub DeleteReference(ByVal sender, ByVal thisUserControl)

        Try

            Dim ret = MsgBox("Are you sure about DELETE?", vbYesNo + vbCritical, "BE CAREFUL")
            If (ret.ToString = "Yes") = True Then



                'The new user control interface,which will delete the reference
                Dim help = Form1.listForUserControlsInterface(thisUserControl)

                strSQL = " DELETE FROM Adevents WHERE adEventID = " & help.getReferenceList(sender).getAdvertEventID & " ;"
                DataBaseLibrary.updateUserControlsFromDataBase(strSQL)

                'Clear the appropriate panel
                help.PanelForReferences.Controls.Clear()

                'Make again the appropriate panel
                help.Size = New System.Drawing.Size(help.Width, help.Height - help.getReferenceList().Count * CONSTANT_PADDING_FOR_UserControlReferences)
                help.Panel1.Size = New System.Drawing.Size(help.Panel1.Width, (help.Panel1.Height - help.getReferenceList().Count * CONSTANT_PADDING_FOR_UserControlReferences))
                help.PanelForReferences.Size = New System.Drawing.Size(help.PanelForReferences.Width, (help.PanelForReferences.Height - help.getReferenceList().Count * CONSTANT_PADDING_FOR_UserControlReferences))

                For i = Form1.numberOfExistingUserControlsInterface - 1 To thisUserControl + 1 Step -1
                    Form1.listForUserControlsInterface(i).Location = New Point((My.Computer.Screen.Bounds.Width - Form1.listForUserControlsInterface(i).Width) / 2, Form1.listForUserControlsInterface(i).Location.Y - help.getReferenceList().Count * CONSTANT_PADDING_FOR_UserControlReferences)
                Next

                'Add to list
                help.getReferenceList().RemoveAt(sender)
                'Add to Interface
                addReferencesToSpecificUserControlInterface(Form1.listForUserControlsInterface(thisUserControl).getAdvertEventID, thisUserControl)



            End If

        Catch ex As Exception
            MsgBox("Problem User Control References deleting,May be you did not Saved it.", vbExclamation, "BE CAREFUL")
        End Try


    End Sub

End Class
